package com.ruoyi.service.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.service.domain.ServiceRule;
import com.ruoyi.service.entity.rule.RuleVO;
import com.ruoyi.service.service.IServiceRuleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 接单退单规则Controller
 * 
 * @author ZDL
 * @date 2025-03-10
 */
@RestController
@RequestMapping("/service/rule")
public class ServiceRuleController extends BaseController
{
    @Autowired
    private IServiceRuleService serviceRuleService;

    /**
     * 查询接单退单规则列表
     */
    //@PreAuthorize("@ss.hasPermi('service:rule:list')")
    //@GetMapping("/list")
    //public TableDataInfo list(ServiceRule serviceRule)
    //{
    //    startPage();
    //    List<ServiceRule> list = serviceRuleService.selectServiceRuleList(serviceRule);
    //    return getDataTable(list);
    //}

    @PreAuthorize("@ss.hasPermi('service:rule:list')")
    @GetMapping("/list")
    public TableDataInfo listNew(ServiceRule serviceRule)
    {
        startPage();
        List<RuleVO> list = serviceRuleService.selectServiceRuleList(serviceRule);
        return getDataTable(list);
    }


    /**
     * 导出接单退单规则列表
     */
    @PreAuthorize("@ss.hasPermi('service:rule:export')")
    @Log(title = "接单退单规则", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ServiceRule serviceRule)
    {
        List<RuleVO> list = serviceRuleService.selectServiceRuleList(serviceRule);
        ExcelUtil<RuleVO> util = new ExcelUtil<RuleVO>(RuleVO.class);
        util.exportExcel(response, list, "接单退单规则数据");
    }

    /**
     * 获取接单退单规则详细信息
     */
    @PreAuthorize("@ss.hasPermi('service:rule:query')")
    @GetMapping(value = "/{ruleId}")
    public AjaxResult getInfo(@PathVariable("ruleId") Long ruleId)
    {
        return success(serviceRuleService.selectServiceRuleByRuleId(ruleId));
    }

    /**
     * 新增接单退单规则
     */
    @PreAuthorize("@ss.hasPermi('service:rule:add')")
    @Log(title = "接单退单规则", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ServiceRule serviceRule)
    {
        return toAjax(serviceRuleService.insertServiceRule(serviceRule));
    }

    /**
     * 修改接单退单规则
     */
    @PreAuthorize("@ss.hasPermi('service:rule:edit')")
    @Log(title = "接单退单规则", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RuleVO serviceRule)
    {
        return toAjax(serviceRuleService.updateServiceRule(serviceRule));
    }

    /**
     * 删除接单退单规则
     */
    @PreAuthorize("@ss.hasPermi('service:rule:remove')")
    @Log(title = "接单退单规则", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ruleIds}")
    public AjaxResult remove(@PathVariable Long[] ruleIds)
    {
        return toAjax(serviceRuleService.deleteServiceRuleByRuleIds(ruleIds));
    }
}
